<template>
  <!-- 角色 -->
  <el-select
    v-model="svalue"
    :size="size"
    filterable
    :clearable="clearable"
    :disabled="disabled"
    :multiple="multiple"
    :placeholder="$t(placeholder)"
    :no-data-text="$t('无数据')"
    :no-match-text="$t('无数据')"
  >
    <el-option
      v-for="item in roleOptions"
      :key="item.id"
      :label="$t(item.roleName)"
      :value="item.id"
    />
  </el-select>
</template>

<script>
import { listRole } from '@/api/system/role'
export default {
  name: 'RoleSelect',
  props: {
    value: {
      type: [String, Array],
      default: ''
    },
    dictionary: {
      type: String,
      default: () => ''
    },
    label: {
      type: String,
      default: () => ''
    },
    option: {
      type: String,
      default: () => ''
    },
    size: {
      type: String,
      default: () => ''
    },
    clearable: {
      type: Boolean,
      default: true
    },
    isCheck: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    disabled: {
      type: Boolean,
      default: false
    },
    multiple: {
      type: Boolean,
      default: false,
      desc: '多选'
    }
  },
  data() {
    return {
      roleOptions: [],
      renederComponent: false,
      svalue: this.value
    }
  },
  watch: {
    value(newVal) {
      console.log(newVal)
      this.svalue = newVal
    },
    svalue(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.$emit('input', this.svalue)
        this.$emit('change', this.svalue)
      }
    }
  },
  created() {
    listRole({}).then(res => {
      this.roleOptions = res.rows
      this.renederComponent = true
    })
  }
}
</script>
